package com.cloud.salon.client.business.controller;

import com.cloud.salon.client.business.service.PreferentialService;
import com.cloud.salon.common.base.entity.business.Preference;
import com.cloud.salon.common.base.response.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description
 * @Author wolf--LZH
 * @CreateDate 2019/5/17 0017 下午 8:21
 */
@RestController
@RequestMapping("preferential")
@Api(tags = "优惠权益管理相关接口")
public class PreferentialController {

    private final String name = "优惠权益";

    @Autowired
    private PreferentialService service;

    @PostMapping("findByAccountAndItem")
    @ApiOperation(value="通过会员账户获取对应的" + name)
    public Res<List<Preference>> findByAccountAndItem(@RequestBody Preference preference) {
        return service.findByAccountAndItem(preference);
    }

    @PostMapping("save")
    @ApiOperation(value="添加一个" + name)
    public Res<Preference> save(@RequestBody Preference preference) {
        return service.save(preference);
    }

    @PostMapping("saveAll")
    @ApiOperation(value="批量添加" + name)
    public Res<List<Preference>> saveAll(@RequestBody List<Preference> preferences) {
        return service.saveAll(preferences);
    }

    @PostMapping("update")
    @ApiOperation(value="修改" + name + "数据")
    public Res<Preference> update(@RequestBody Preference preference) {
        return service.update(preference);
    }

    @PostMapping("updateAll")
    @ApiOperation(value="批量修改" + name + "数据")
    public Res<List<Preference>> updateAll(@RequestBody List<Preference> preferences) {
        return service.updateAll(preferences);
    }

    @PostMapping("deleteById")
    @ApiOperation(value="通过id删除对应" + name)
    public Res<Boolean> deleteById(@RequestBody Integer id) {
        return  service.deleteById(id);
    }

    @PostMapping("deleteByIdAll")
    @ApiOperation(value="通过id集合批量删除" + name)
    public Res<Integer> deleteByIdAll(@RequestBody List<Integer> ids) {
        return service.deleteByIdAll(ids);
    }
}
